package com.ftp.job;

import com.ftp.config.FtpConfig;
import com.ftp.util.FtpUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import java.io.File;

/**
 * Created by Administrator on 2019-4-2 0002.
 */
@Component
@Order(value = 1)
public class FtpMain implements CommandLineRunner{
    private final static Logger log = LoggerFactory.getLogger(FtpMain.class);

    @Autowired
    FtpConfig ftpConfig;
    @Override
    public void run(String... strings) throws Exception {
        //ftp初始化
        if (ftpConfig.isEnable()) {
            log.info("--------------ftp初始化-------------start");
            FtpUtil.init(ftpConfig);
            log.info("--------------ftp初始化-------------end");
            File file = new File("ftp-test.txt");

            if(file.exists()){
                String path = "ftptest"+ File.separator;
                String filename = file.getName();
                FtpUtil.ftpUpload(file,path);
            }
        }
    }

    public static void main(String[] args) {
        File file = new File("ftp-test.txt");
        System.out.println(file.exists());
        System.out.println(file.getAbsolutePath());
        System.out.println(file.getPath());
    }
}
